package com.wits.platform.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import com.wits.platform.common.JsonDateValueProcessor;
import com.wits.platform.common.constants.SysTabConstants;
import com.wits.platform.common.utils.DateUtil;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonBeanProcessor;

@Entity
@Table(name = "wits_employee")
public class Employee  extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5405683335247662111L;
	
	public Employee(){
		
	}

	/**
	 * 员工编号
	 */
	private String empId;
	
	/**
	 * 员工姓名
	 */
	private String empNameC;
	
	/**
	 * 员工英文姓名
	 */
	private String empNameE;
	
	/**
	 * 电子邮件
	 */
	private String empEmail;
	
	/**
	 * 生日
	 */
	private Date dateBirth;
	
	/**
	 * 到职日期
	 */
	private Date dateReg;
	
	/**
	 * 离职日期
	 */
	private Date dateRsn;
	
	/**
	 * 员工属性
	 */
	private String empType;
	
	/**
	 * 职称
	 */
	private String empTitle;
	
	/**
	 * 是否在职
	 * (默认T,在职)
	 */
	private String isResign=SysTabConstants.SYSTAB_D_TNF_T;

	
	private Department department;


	@Id
	@Column(name="emp_id",length=36)
	public String getEmpId() {
		return empId;
	}

	public void setEmpId(String empId) {
		this.empId = empId;
	}

	@Column(name="emp_name_c",length=100)
	public String getEmpNameC() {
		return empNameC;
	}

	public void setEmpNameC(String empNameC) {
		this.empNameC = empNameC;
	}

	@Column(name="emp_name_e",length=100)
	public String getEmpNameE() {
		return empNameE;
	}

	public void setEmpNameE(String empNameE) {
		this.empNameE = empNameE;
	}

	@Column(name="emp_email",length=100)
	public String getEmpEmail() {
		return empEmail;
	}

	public void setEmpEmail(String empEmail) {
		this.empEmail = empEmail;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "date_birth")
	public Date getDateBirth() {
		return dateBirth;
	}

	public void setDateBirth(Date dateBirth) {
		this.dateBirth = dateBirth;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "date_reg")
	public Date getDateReg() {
		return dateReg;
	}

	public void setDateReg(Date dateReg) {
		this.dateReg = dateReg;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "date_rsn")
	public Date getDateRsn() {
		return dateRsn;
	}

	public void setDateRsn(Date dateRsn) {
		this.dateRsn = dateRsn;
	}

	@Column(name="emp_type",length=36)
	public String getEmpType() {
		return empType;
	}

	public void setEmpType(String empType) {
		this.empType = empType;
	}

	@Column(name="emp_title",length=36)
	public String getEmpTitle() {
		return empTitle;
	}

	public void setEmpTitle(String empTitle) {
		this.empTitle = empTitle;
	}

	@Column(name="is_resign",length=1)
	public String getIsResign() {
		return isResign;
	}

	public void setIsResign(String isResign) {
		this.isResign = isResign;
	}

	@ManyToOne
	@JoinColumn(name="dept_id")
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}
	

	@Override
	public String display() {
		// TODO Auto-generated method stub
		return this.empNameC;
	}
	
	
	private static JsonConfig jsonConfig = new JsonConfig();


	@Transient
	public static JsonConfig getJsonConfig() {
		return jsonConfig;
	}
	
	static{

		jsonConfig.registerJsonBeanProcessor(Employee.class, new JsonBeanProcessor(){
			@Override
			public JSONObject processBean(Object bean, JsonConfig jConf) {
				if(!(bean instanceof Employee)){
		            return new JSONObject(true);
		         }
				Employee emp = (Employee) bean;
				Department dept=emp.getDepartment();
		         return new JSONObject()
		            .element("empId",emp.getEmpId())
		            .element("empNameC",emp.getEmpNameC())
		            .element("empNameE", emp.getEmpNameE())
		            .element("deptName",dept!=null?dept.getDeptId():"")
		            .element("empType", emp.getEmpType())
		            .element("dateReg", DateUtil.format(emp.getDateReg(),"yyyy-MM-dd"));
		      }
			});
		
		
	}

}
